module.exports ={
	/**
	  * 滑到顶部
	  */
	toTop: function(){
		let top = document.documentElement.scrollTop || document.body.scrollTop
		const timeTop = setInterval(() => {
			document.body.scrollTop = document.documentElement.scrollTop = top -= 50
			if (top <= 0) {
				clearInterval(timeTop)
			}
		}, 10)
	},
	/**
	  * str按逗号分割成数组
	  */
	stringToArr: function(str){
		if(!str){
			return ''
		}else{
			return str.split(',')
		}
	},
	/**
	  * arr数组拼接成字符串
	  */
	arrToString: function(arr){
		if(arr==[]){
			return
		}
		var temp = ''
		for(var i in arr){
			temp += arr[i] +','
		}
		temp = temp.substring(0,temp.length - 1)
		return temp
	},
	/**
	  * 时间戳转为时间
	  * 1.时间戳为10位需*1000，时间戳为13位的话不需乘1000
	  * @param timestamp
	  * @returns {yyyy-mm-dd hh:mm:ss}
	  */
	timestampToTime : function(timestamp,type){
		timestamp = parseInt(timestamp)
		var date = new Date(timestamp * 1000)
		var Y = date.getFullYear() + '-'
		var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-'
		var D = date.getDate() + ' '
		var h = date.getHours() + ':'
		var m = (date.getMinutes() < 10 ? '0'+(date.getMinutes()) : date.getMinutes()) + ':'
		var s = (date.getSeconds() < 10 ? '0'+(date.getSeconds()) : date.getSeconds())
		var str = Y+M+D+h+m+s
		if(type == 'y-m-d'){
			str = Y+M+D
		}
		return str
	},
	/**
	  * 时间转为时间戳
	  * @returns timestamp
	  */
	timeToTimestamp : function(time){
		if(!time){
			return ''
		}
		var date = new Date(time)
		return date.getTime() / 1000
	},
	/**
	 * 获取年月日
	 * day -2 前天
	 * day -1 昨天
	 * day 0 今天
	 * day 1 明天
	 * day 2 后天
	 * day 3 大后天
	 */
	getDates : function(day){
		var today = new Date()
		var targetday_milliseconds=today.getTime() + 1000*60*60*24*day
		today.setTime(targetday_milliseconds)
		var tYear = today.getFullYear()
		var tMonth = today.getMonth()
		var tDate = today.getDate()
		tMonth = this.doHandleMonth(tMonth + 1)
		tDate = this.doHandleMonth(tDate)
		return tYear+"-"+tMonth+"-"+tDate
	},
	doHandleMonth : function(month){
		var m = month
		if(month.toString().length == 1){
		   m = "0" + month
		}
		return m
	},
	/**
	 * 锚点滚动
	 * @param { string | number } selector
	 */
	goAnchor: function(selector){
	  // 移动距离
	  let top = 0
	  // 当前滚动条位置
	  const scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop
	  // 若为指定距离
	  if (typeof selector === 'number') {
	    top = selector - scrollTop
	  } else {
	    const anchor = document.querySelector(selector) || { offsetTop: 0 }
	    top = anchor.offsetTop - scrollTop - 300
	  }
	  window.scrollBy({ top, behavior: 'smooth' })
	}
}
